package com.llc.mall.auth.interfaces;

import com.llc.mall.auth.application.command.UserAppService;
import com.llc.mall.auth.application.commands.UserLoginCommand;
import com.llc.mall.auth.interfaces.vo.TokenInfoVo;
import com.llc.mall.common.core.response.ServerResponseEntity;
import com.mall4j.cloud.api.auth.vo.TokenInfoVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import jakarta.validation.Valid;

@Tag(name = "登录")
@RestController
public class LoginController {

    @Resource
    private UserAppService userAppService;

    @Operation(summary = "账号密码", description = "通过账号登录，还要携带用户的类型，也就是用户所在的系统")
    @PostMapping("/ua/login")
    public ServerResponseEntity<TokenInfoVo> login(@Valid @RequestBody UserLoginCommand userLoginCommand) {
        TokenInfoVo result = userAppService.login(userLoginCommand);
        return ServerResponseEntity.success(result);
    }

    @Operation(summary = "退出登陆", description = "点击退出登陆，清除token，清除菜单缓存")
    @PostMapping("/login_out")
    public ServerResponseEntity<TokenInfoVO> loginOut() {
        userAppService.loginOut();
        return ServerResponseEntity.success();
    }

}
